package com.zhuangfei.hos_timetableview.custom;

import com.zhuangfei.timetable.operater.SimpleOperater;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.utils.LayoutAlignment;

/**
 * 自定义的课表业务操作者，以实现列宽设置。
 *
 * @version 2.0.6
 * Created by Liu ZhuangFei on 2018/9/1.
 */
public class CustomOperater extends SimpleOperater {
    private static final String TAG = "CustomOperater";
    private float[] weights; // 宽度权重

    public CustomOperater() {
        weights = new float[7];
        for (int i = 0; i < weights.length; i++) {
            weights[i] = 1;
        }
    }

    @Override
    public void applyWidthConfig() {
        super.applyWidthConfig();
        if (weights == null){
            return;
        }
        for (int i = 0; i < panels.length; i++) {
            DirectionalLayout.LayoutConfig lp = new DirectionalLayout.LayoutConfig(0, DirectionalLayout.LayoutConfig.MATCH_PARENT, LayoutAlignment.START, weights[i]);
            panels[i].setLayoutConfig(lp);
        }
    }

    public void setWidthWeights(float[] weights) {
        if (weights == null || weights.length < 7){
            return;
        }
        this.weights = weights;
    }

    public float[] getWeights() {
        return weights;
    }
}
